﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Products;
using MinhTuan;

public partial class admin_product_AddProduct : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        String[] admin = Session["Admin"].ToString().Split(',');
        if (int.Parse(admin[0]) < 0)
        {
            Response.Redirect("http://localhost:2011/didong/admin/login.aspx");
        }
        if (!Page.IsPostBack)
        {

            Binhdata();
        }
    }
    protected void Binhdata()
    {
        this.Dropcategory.DataSource = Category.GetCategory();
        this.Dropcategory.DataBind();
        this.Dropbrand.DataSource = Brand.GetBrand();
        this.Dropbrand.DataBind();
        this.drlType.DataSource = Class.GetClass();
        this.drlType.DataBind();
    }
    protected void Dropcategory_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void BtnCancel_Click(object sender, EventArgs e)
    {

    }
    protected void BtnSubmit_Click(object sender, EventArgs e)
    {
            Product myproduct = new Product();
            myproduct.Products_Name = txtname.Text;
            myproduct.Brand_Id = int.Parse(Dropbrand.SelectedValue.ToString());
            myproduct.Category_Id = int.Parse(Dropcategory.SelectedValue.ToString());
            myproduct.Class_Id = int.Parse(drlType.SelectedValue.ToString());
            myproduct.Products_Price = Convert.ToInt32(txtprice.Text);
            myproduct.Products_Quantity = int.Parse(txtquantity.Text);
            myproduct.Products_Title = Access.RemoveVietnameseSigns(txtname.Text);
            myproduct.Products_Unit = txtunit.Text;
            if (fuImage.FileName!= null) myproduct.Products_Image = "image/product/" + fuImage.FileName;

            myproduct.Products_Detail = CKEditor1.Text;
            myproduct.Ishot = ckhighlights.Checked;
            myproduct.IsNew = cknews.Checked;
            myproduct.Products_Warranty = txtwaranry.Text;
            myproduct.Products_Origin = "Hang moi";
            myproduct.Products_DescriptionImage = txtname.Text;
            myproduct.Products_DateUpdate = DateTime.Now;
            myproduct.IsActive = true;
            myproduct.Ishot = false;
            myproduct.IsNew = true;
            Boolean Result = Product.Add_Product(myproduct);
            if (Result == true)
            {
                Lmessage.Text = "<strong>Thêm mới thành công</strong>";
            }
            else Lmessage.Text = "<strong>Thêm mới không thành công</strong>";

        
    }
    protected void CKEditor1_TextChanged(object sender, EventArgs e)
    {

    }
}
